package com.mskj.zxmy.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mskj.zxmy.dto.Ck03ListingQuery;
import com.mskj.zxmy.entity.Ck03Listing;
import com.mskj.zxmy.mapper.Ck03ListingMapper;
import com.mskj.zxmy.mapper.StockInMapper;
import com.mskj.zxmy.mapper.UserMapper;
import com.mskj.zxmy.service.Ck03ListingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class Ck03ListingServiceImpl implements Ck03ListingService {

    @Autowired
    private Ck03ListingMapper ck03ListingMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private StockInMapper stockInMapper;


//    @Override
//    public PageInfo<Ck03Listing> searchCk03ListingsWithPage(Ck03ListingQuery query) {
//        Map<String, Object> params = new HashMap<>();
//        params.put("documentType", query.getDocumentType());
//        params.put("repositoryNumber", query.getRepositoryNumber());
//        params.put("operator", query.getOperator());
//        params.put("repositoryDate", query.getRepositoryDate());
//        params.put("approvalStatus", query.getApprovalStatus());
//        params.put("productionTasks", query.getProductionTasks());
//        params.put("linkQualityCheckPlan", query.getLinkQualityCheckPlan());
//        params.put("associatedSuppliers", query.getAssociatedSuppliers());
//        params.put("singleBatch", query.getSingleBatch());
//        params.put("repositoryStatus", query.getRepositoryStatus());
//        params.put("sortField", query.getSortField());
//        params.put("isDesc", query.getIsDesc() != null && query.getIsDesc());
//        params.put("startDate", query.getStartDate());
//        params.put("endDate", query.getEndDate());
//
//        // 设置分页
//        PageHelper.startPage(query.getPageNum(), query.getPageSize());
//
//        List<Ck03Listing> result = ck03ListingMapper.searchCk03Listings(params);
//        for (Ck03Listing ck03Listing : result) {
//            ck03Listing.setOperator(userMapper.findNickByMemberId(ck03Listing.getOperator()));
//        }
//        return new PageInfo<>(result);
//    }
@Override
public PageInfo<Ck03Listing> searchCk03ListingsWithPage(Ck03ListingQuery query) {
    PageHelper.startPage(query.getPageNum(), query.getPageSize());
    List<Ck03Listing> list = ck03ListingMapper.searchCk03ListingsWithPage(query);
    for (Ck03Listing ck03Listing : list) {
        ck03Listing.setOperator(userMapper.findNickByMemberId(ck03Listing.getOperator()));
        ck03Listing.setProductionTasks01(stockInMapper.getProductionTasksById(ck03Listing.getProductionTasks()));
        ck03Listing.setTasks(stockInMapper.getTasksById(ck03Listing.getTasks()));
    }
    return new PageInfo<>(list);
}
}